package com.heima.behavior.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.apis.behavior.ApReadBehaviorControllerApi;
import com.heima.behavior.service.ApReadBehaviorService;
import com.heima.model.behavior.dtos.ReadBehaviorDto;
import com.heima.model.behavior.pojos.ApReadBehavior;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/read_behavior")
public class ApReadBehaviorController implements ApReadBehaviorControllerApi {
    @Autowired
    private ApReadBehaviorService apReadBehaviorService;
    @PostMapping
    @Override
    public ResponseResult readBehavior(@RequestBody ReadBehaviorDto dto) {
        return apReadBehaviorService.readBehavior(dto);
    }
    // 查询阅读行为数据
    @Override
    @PostMapping("queryReadCount")
    public List<ApReadBehavior> queryReadCount(@RequestBody List<Long> articleList) {

        System.out.println("articleList ================================== " + articleList);

        return apReadBehaviorService.list(
                Wrappers.<ApReadBehavior>lambdaQuery()
                        .in(ApReadBehavior::getArticleId, articleList)
        );
    }
}